﻿using System;
using System.Web.Mvc;

namespace Dqaqs.Web.Common
{
	public class EditableController : Controller
	{
		protected MenuService MenuService { get; private set; }
		protected ProjectContext ProjectContext { get; private set; }

		protected override void Initialize(System.Web.Routing.RequestContext requestContext)
		{
			base.Initialize(requestContext);

			MenuService = new MenuService(this);
			ProjectContext = new ProjectContext(this);
		}

		protected ActionResult ShowError(string error)
		{
			ViewBag.ErrorMsg = error;
			return View("../Common/CustomError");
		}

		protected bool HandleException(Exception ex)
		{
			if (ex==null)
				return false;
			LastError = ShowError(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
			return true;
		}

		protected ActionResult LastError { get; private set; }
	}
}